#include<iostream>
using namespace std;
const int N = 10;
int arr[N][N];

bool check() {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            bool ar[10];
            for (int k = 0; k < 3; k ++) {
                for (int p = 0; p < 3; p++) {
                    int x = i * 3 + k, y = j * 3 + p;
                    //  cout << arr[x][y] <<",";
                    //  cout << x << " " << y <<endl;
                    if(ar[arr[x][y]]) return false;
                    ar[arr[x][y]] = true;
                }
                // cout <<endl;
            }
            // cout <<endl;
        }
    }
    return true;
}
int n = 0;

void swapPosition(int r, int c) {
    n++;
    // cout << r << " "<<c << endl;
    if (c == 9) {
      /*  if (check()) {
            // 打印答案
            for (int j = 0; j < 9; j++) {
                for (int k = 0; k < 9; k++) {
                    cout << arr[j][k] << " ";
                }
                cout<< endl;
            }
            cout<< endl;
        }*/
        swapPosition(r + 1, 0);
        return;
    }
    for (int i = c; i < 9; i++) {
        swap(arr[r][c], arr[r][i]);
        swapPosition(r, c + 1);
        swap(arr[r][c], arr[r][i]);
    }
    
}

// 创建题目矩阵
void getTeam() {
    // 初始化
    for (int i = 0; i < 9; i++) {
        for (int j = 0; j < 9; j++) {
            arr[i][j] = j + 1;
            // cout << arr[i][j]<<" ";
        }
        // cout<<endl;
    }
        // cout<<endl;
    // 随机交换位置
    swapPosition(0, 0);
}
// 挖空 num表示挖几个
void getQuestion(vector<vector<int>> arr, int num) {
    int rowNum = 9; //一行有几个
    bool haveGetFlag[9][9];
    memset(haveGetFlag, false, sizeof(haveGetFlag));
    while(num) {
        int x = random() % rowNum;
        int y = random() % rowNum;
        if (haveGetFlag[x][y]) continue;
        haveGetFlag[x][y] = true;
        arr[x][y] = 0;
        num--;
    }
}

int main() {
    getTeam();
    cout<<n;
   /* int res = 1;
    for (int i = 9;i > 1; i--) {
        res *= i;
    }
    cout << res;
    return 0;*/
}